
<template>
  <div class="registration_wrapper">
    <!-- 标题 -->
    <div class="title_container">
      <h2>{{ hosDetailByHosname?.hospital.hosname }}</h2>
      <div class="level">
        <el-icon><Star /></el-icon>
        <span>{{ hosDetailByHosname?.hospital.param.hostypeString }}</span>
      </div>
    </div>
    <!-- logo及路线 -->
    <div class="logo-route">
      <img class="hospital-img" :src="logoUrl" />
      <div class="m-20">
        <h3>挂号规则</h3>
        <span class="m-r-10"
          >预约周期：{{ hosDetailByHosname?.bookingRule.cycle }}天</span
        >
        <span class="m-r-10"
          >放号时间：{{ hosDetailByHosname?.bookingRule.releaseTime }}</span
        >
        <span class="m-r-10"
          >停挂事件：{{ hosDetailByHosname?.bookingRule.stopTime }}</span
        >
        <br />
        具体地址：{{ hosDetailByHosname?.hospital.param.fullAddress }}
        <br />
        规划路线：{{ hosDetailByHosname?.hospital.route }}
        <br />
        退号时间：就诊前一工作日{{
          hosDetailByHosname?.bookingRule.quitTime
        }}前取消
        <h3>医院预约规则</h3>
        <ol>
          <li
            v-for="(item, index) in hosDetailByHosname?.bookingRule.rule"
            :key="index"
          >
            {{ index + 1 + "." + item }}
          </li>
        </ol>
      </div>
    </div>
    <!-- 科室列表 -->
    <div>
      <el-tabs tab-position="left" type="border-card" class="demo-tabs">
        <el-tab-pane v-for="item in hosDepartmentList" :key="item.depcode">
          <template #label>
            <div>
              {{ item.depname }}
            </div>
          </template>
          <!-- content -->
          <div class="content">
            <div class="title">{{ item.depname }}</div>
            <ul class="rightItemContainer">
              <li class="rightItem" v-for="dep in item.children" :key="dep.depcode" @click="departmentClick(hosDetailByHosname?.hospital.hosname as string,item.depname,dep.depname,dep.depcode)">{{ dep.depname }}</li>
            </ul>
          </div>

          <!--  -->
        </el-tab-pane>
      </el-tabs>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, onMounted, ref } from "vue";
import { useRoute,useRouter } from "vue-router";

export default defineComponent({
  name: "Registration",
});
</script>

<script setup lang="ts">
import {
  reqHosDetailByHosname,
  reqHosDepartmentList,
} from "@/api/registration";
import type {
  typeHosDetailByHosname,
  typeHosDepartmentListResponse,
} from "@/api/registration";
//获取路由对象
const route = useRoute();
const router = useRouter();
//数据1：动态路由传入的参数
const code = ref("");
//数据2: 医院预约挂号详情
const hosDetailByHosname = ref<typeHosDetailByHosname>();
//数据3：base64格式图片logo
const logoUrl = ref("");
//数据4：医院科室列表
const hosDepartmentList = ref<typeHosDepartmentListResponse>([]);

//方法1:获取医院预约挂号详情
const getHosDetailByHosname = async () => {
  try {
    const result = await reqHosDetailByHosname(code.value);
    console.log("预约挂号详情", result);
    hosDetailByHosname.value = result;
    logoUrl.value = "data:image/png;base64," + result.hospital.logoData;
  } catch (error) {}
};
//方法2：获取医院科室列表
const getHosDepartmentList = async () => {
  try {
    const result = await reqHosDepartmentList(code.value);
    console.log("医院科室列表", result);
    hosDepartmentList.value = result;
  } catch (error) {}
};
//方法3:  科室点击事件
const departmentClick = (hosname:string,depname1:string,depname2:string,depcode:string) => {
  console.log("科室",hosname,depname1,depname2,depcode,code.value);
  router.push({
    path:`/hospital/registration/registration_step_1`,
    query:{
      code:code.value,
      hosname,
      hoscode:code.value,
      depcode:depcode,
      depname1,
      depname2
    }
  })
}


onMounted(() => {
  console.log("route", route.query);
  //初始化1：获取动态路由传入的query参数
  code.value = route.query.code as string;
  //初始化2:获取医院预约挂号详情
  getHosDetailByHosname();
  //初始化3：获取医院科室列表
  getHosDepartmentList();
});
</script>

<style scoped>
.registration_wrapper {
  flex-grow: 1;
  flex: 1;
  padding: 20px;
}
/* 标题 */
.title_container {
  display: flex;
}
.title_container h2 {
  margin-top: 0;
  margin-bottom: 0.5em;
  font-size: 21px;
  color: #000000d9;
  font-weight: 500;
}
.title_container .level {
  margin-left: 10px;
  margin-top: 5px;
}

.title_container .level span {
  font-size: 16px;
}
/* logo-route */
.logo-route {
  display: flex;
}
.hospital-img {
  width: 80px;
  height: 80px;
  border-radius: 40px;
  margin-left: 10px;
  transition: all 0.2s linear;
  /* background-color: #000;  */
}
.m-20 {
  margin: 20px;
  flex: 1;
  font-size: 14px;
  line-height: 20px;
}
.m-20 h3 {
  margin-top: 0;
  margin-bottom: 0.5em;
  color: #000000d9;
  font-weight: 500;
}
.m-r-10 {
  margin-right: 10px;
  font-size: 14px;
}

/* 科室列表 */
.demo-tabs >>> .el-tabs__item {
  justify-content: space-around;
  font-size: 12px;
}
.el-tabs--border-card >>> .el-tabs__header .el-tabs__item.is-active {
  color: red;
}
.el-tabs--border-card
  >>> .el-tabs__header
  .el-tabs__item:not(.is-disabled):hover {
  color: red;
}
.el-tabs--border-card >>> .el-tabs__content {
  padding: 0;
}
.content .title {
  height: 26px;
  background-color: rgb(248, 248, 248);
  color: #93999f;
  line-height: 26px;
  font-size: 12px;
  font-weight: 700;
  padding-left: 12px;
}
.rightItemContainer {
  display: flex;
  flex-wrap: wrap;
  width: 880px;
  font-size: 14px;
}
.rightItemContainer .rightItem {
  width: 28%;
  padding: 10px 20px;
  cursor: pointer;
}
</style>



